package com.softer.chengxin.param.dao;

import com.softer.chengxin.param.entity.Grade;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Gong Zhiyang
 * @date 2019/12/14
 */
@Mapper
@Repository
public interface GradeDao {
    /**
     * 保存评级设置，根据主键，有则修改，无则增加
     *
     * @param grade 评级
     * @return 保存结果
     */
    @Insert("INSERT INTO grade_info(id,level,bad_info,bigger_score,smaller_score,bigger_sign,smaller_sign,gmt_create,creater) " +
            " VALUES(#{g.id},#{g.level},#{g.badInfo},#{g.biggerScore},#{g.smallerScore},#{g.biggerSign},#{g.smallerSign},now(),#{g.creater})" +
            " ON DUPLICATE KEY UPDATE level=#{g.level},bad_info=#{g.badInfo},bigger_score=#{g.biggerScore},smaller_score=#{g.smallerScore},bigger_sign=#{g.biggerSign}," +
            "smaller_sign=#{g.smallerSign},gmt_modify=now(),modifier=#{g.modifier}")
    int save(@Param("g") Grade grade);
    /**
     * 获取评级列表
     *
     * @return 列表
     */
    @Select("SELECT id,`level`,bad_info as badInfo,bigger_score as biggerScore,smaller_score as smallerScore,bigger_sign as biggerSign,smaller_sign as smallerSign FROM grade_info")
    List<Grade> getList();
    /**
     * 删除评级
     *
     * @param id      评级ID
     * @return 删除结果
     */
    @Delete("DELETE FROM grade_info WHERE id=#{id}")
    int delete(@Param("id") int id);
    /**
     * 查询信用等级列表
     * 用于下拉列表
     *
     * @return 信用等级下拉列表
     */
    @Select("SELECT `level` FROM grade_info")
    List<String> getLevelList();
}
